package com.判断B是不是A的子树;

public class Solution {
    public boolean HasSubtree(TreeNode root1,TreeNode root2) {
    	
    	boolean result = false;
    	if(root1==null||root2==null) {
    		return false;
    	}
    	else {
    		if(root1.val == root2.val) {
    			result=Keepfindsubtree(root1, root2);
    		}
    		if(!result){
//    			result = HasSubtree(root1.left, root2)||HasSubtree(root1.right, root2);
    			result = HasSubtree(root1.left, root2);
    		}
    		if(!result) {
    			result = HasSubtree(root1.right, root2);
    		}
    	}
    	return result;
        
    }
    public boolean Keepfindsubtree(TreeNode root1,TreeNode root2) {
    	if(root2==null)
    		return true;
    	if(root1==null)
    		return false;
    	if(root1.val!=root2.val) 
    		return false;
    	
		return Keepfindsubtree(root1.left, root2.left)&&Keepfindsubtree(root1.right, root2.right);
    	
    }
}
